package com.duowei.diandan.view;

import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;

import java.util.Locale;

public class PriceTextView extends AppCompatTextView {

    public PriceTextView(Context context) {
        super(context);
    }

    public PriceTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PriceTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setPrice(Float val) {
        setPrice("¥%s", val);
    }

    public void setPrice(String format, Float... val) {
        if (val == null) {
            setText(null);
        } else {
            String[] strArray = new String[val.length];
            for (int i = 0; i < val.length; i++) {
                strArray[i] = String.valueOf(val[i]).replaceAll("\\.?0*$", "");
            }

            setText(String.format(Locale.CHINA, format, (Object[]) strArray));
        }
    }
}
